require("../util.js");
require("../component/components.js");
require("../../jsMt/util.js");
var vm = new Vue({
    el:"#orderInfo",
    data:{
        uid:"",
        orderNumber:"",
        preorderList:{},
        address:{},
        isScreen:"",
        state:"",
        imgSrc:"",
        number:"",
        orderInfo:{},
        type:"",
        num:""
    },
    mounted:function(){
        this.searchObject = this.getQueryStringArgs();
        this.uid=this.searchObject&&this.searchObject.uid;
        this.orderNumber=this.searchObject&&this.searchObject.orderNumber;
        this.type=this.searchObject&&this.searchObject.type;
        this.userOrderInfo();
    },
    methods: {
        //后退
        getBack: function () {
            history.go(-1);
        },
        bgimg: function (url) {
            url = url ? url : "";
            return {
                "background-image": 'url("' + url + '"),url("")'
            }
        },
        /*获取查询字符对象*/
        getQueryStringArgs: function () {
            //取得查询字符串并去掉开头的问号
            var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
                args = {},
                items = qs.length ? qs.split("&") : [],
                item = null,
                name = null,
                value = null,
                len = items.length;
            for (var i = 0; i < len; i++) {
                item = items[i].split("=");
                name = item[0];
                value = item[1];
                if (name.length) {
                    args[name] = value;
                }
            }
            return args;
        },
        //订单详情
        userOrderInfo:function(){
            var that=this;
            var data={
                loginUid:that.uid,
                orderNumber:that.orderNumber
            };
            that.ajax({url:"/purchase/userOrderInfo",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.orderInfo=b.json.data;
                    that.address=that.orderInfo.address;
                    that.num=that.orderInfo.afterList.length;
                    console.log(that.num)

                }else{
                    vm.$refs.prompt.toast("获取订单详情失败！");
                }
            });
        },
        getClose:function(){
            var that=this;
            var data = [{ "id": "缺货", "value": "缺货" },{ "id": "买家不想要了", "value": "买家不想要了" }, { "id": "其它原因", "value": "其它原因" }];
            var bankSelect = new IosSelect(1,
                [data],
                {
                    container: '.provingMode',
                    itemHeight: 30,
                    itemShowCount: 3,
                    callback: function (selectOneObj) {
                        console.log(selectOneObj.value)
                        that.sellerupdatecloseorder(selectOneObj.value);
                    }
                });
        },
        //关闭订单
        sellerupdatecloseorder:function(reason){
            var that=this;
            var data={
                loginUid:that.uid,
                orderNumber:that.orderNumber,
                reason:reason
            };
            console.log(data)
            that.ajax({url:"/happyi/sellerupdatecloseorder",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0){
                    this.getBack();
                }else{
                    vm.$refs.prompt.toast("关闭订单失败！");
                }
            });
        },
        getNext:function(num){
            if(num==1){  //发货
                location.href="/happyi/deliverGoods?type=1&uid="+this.uid+"&orderNumber="+this.orderNumber;
            }else if(num==2){  //修改价格
                location.href="/happyi/modifyPrice?uid="+this.uid+"&orderNumber="+this.orderNumber;
            }else if(num==3){  //修改地址
                location.href="/addAddress?type=3&uid="+this.uid+"&addressId="+this.address.addressId;
            }else if(num==4){ //物流
                location.href="/happyi/refundInfo?type=3&orderNumber="+this.orderInfo.courierNumber+"&uid="+this.uid+"&courier="+encodeURI(this.orderInfo.courier)
            }
        }
    }
});
